﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BW.EatRabbit.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UploadController : ControllerBase
    {
        private readonly IWebHostEnvironment webHostEnvironment;
        public UploadController(IWebHostEnvironment webHostEnvironment)
        {
            this.webHostEnvironment = webHostEnvironment;

        }
        [HttpPost]
        public IActionResult Uplock(IFormFile file)
        {
            string str = Guid.NewGuid().ToString() + file.FileName;
            string path = webHostEnvironment.WebRootPath + @"\pic\" + str;
            using (FileStream fs=System.IO.File.Create(path))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            string constr = "http://localhost:5219/" + @"/pic/" + str;
            return Ok(constr);
        }
    }
}
